package puppy.eval;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;

import puppy.graph.AgeAggregator;


import algorithms.PageRankSuggestions;
import algorithms.RandomWalkLatentEngine;

import algorithms.models.QueryTagsModel;
import algorithms.models.QueryTopicsModel;

public class EvaluateQuerySuggestionsRWLauncher {
	
	// model parameters
	
	//static String path = "../data/graph/last/delcious_graph_merged_enriched_inline_kids.txt";
//	static String path = "../data/graph/plus/delicious_graph_plus.txt";
	static String path = "../data/graph/plus/graph_adults_sample2.txt";
	
	//static String path = "../data/graph/last/samplet.txt";
	static String node_node = "../data/graph/last/tags_dmoz_bigram_subset_merged_groups_kids.txt";
	static String query_tags = "../data/query_tags/query_and_tags_sorted_aol.txt";
	static String  topics_docs ="../data/topics/kids_simple30/100_output_doc_topics.txt";
	static String  topics_words  ="../data/topics/kids_simple30/topic_given_word_normalized.txt";
	static String  query_topics_path  ="../data/topics/kids_simple30/query/100_output_doc_topics_enriched.txt";
	static String topics_probabilities ="../data/topics/kids_simple30/topics_probabilities.txt";
	static String output_path="/home/sergio/projects/learning_rank/query_suggestions/dmoz/features/rw_ranks.txt";
	
	static float epsilon=0.001f;
	static float alpha=0.2f;
	static int max_iterations=3;
	int n_gram_weight=2;
	int mimimum_length_ngram= 2;
	
	//gold set parameters
	
	
	//static String evaluation_path = "../data/gold_set/aol_query_reformulations/kids_long_click.txt";
//	static String evaluation_path = "../data/gold_set/aol_query_reformulations/ydir/with_click.txt";
	//static String evaluation_path = "../data/gold_set/aol_query_reformulations/sample.txt";
	
	//static String evaluation_path="../data/gold_set/ydir_query_reformulations/with_long_click.txt";
	static String evaluation_path="../data/gold_set/y_reformulations/years_10_12.txt";
	
	static String log_type="";
	static HashSet<String> valid_ages= new HashSet<String>();
	
	
	static boolean onlyClicks=true;
	static int duration =20;
	static boolean onlyManual=false;
	
	
	
	public static void main(String argsp[]) throws IOException {

		valid_ages.add("kids");
		//valid_ages.add("kids-teens-mteens");
		//valid_ages.add("adults");
	
		EvaluateSuggestions eval = 
				new EvaluateSuggestions(evaluation_path,log_type, valid_ages,onlyClicks,duration, onlyManual, output_path);
		
		System.out.println("evaluation module loaded");
		
		AgeAggregator agg= new AgeAggregator(valid_ages);
		
		topics_words=null;
		PageRankSuggestions page = new PageRankSuggestions(path,node_node,topics_words, topics_docs,topics_probabilities, agg,alpha,max_iterations); //ranker
		
		
		//RandomWalkLatentEngine page = new RandomWalkLatentEngine(path,node_node,topics_words, topics_docs,topics_probabilities, agg,alpha,max_iterations); //ranker

		
		System.out.println("ranking module loaded");
		
		HashSet<String> queries_to_eval=new HashSet<String>();
		
		initQueriesToEval(eval.getGoldStandard(), queries_to_eval);
		
		QueryTagsModel querytags = new QueryTagsModel(query_tags, queries_to_eval);
	
		QueryTopicsModel querytopics =new QueryTopicsModel(query_topics_path,queries_to_eval);
		//load bank of queries and their tags
		System.out.println("query models loaded");
		
		eval.performEvaluation(page,querytags, querytopics);
		
		
	}
	
	public static void initQueriesToEval( Hashtable<String,Hashtable<String, ArrayList<String>>> gold, HashSet<String>queries_to_eval){
		Enumeration<String> keys = gold.keys();
		while(keys.hasMoreElements()){
			
			String key =keys.nextElement();
			Hashtable<String, ArrayList<String>> qq = gold.get(key);
		
			queries_to_eval.addAll(qq.keySet());
			
		}
	}
}
